package com.homework.action;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.homework.bean.PageInfoBean;
import com.homework.bean.QuestionBean;
import com.homework.bean.UserAnswerListBean;
import com.homework.bean.UserQuestionBean;
import com.homework.service.QuestionService;

public class QuestionGetAction {
	
	private QuestionService questionService;
	private int courseId;
	private int questionId;
	private int intPage;
	
	public QuestionGetAction() {
		// TODO Auto-generated constructor stub
		questionService = new QuestionService();
	}
	
	public int getCourseId() {
		return courseId;
	}

	public void setCourseId(int courseId) {
		this.courseId = courseId;
	}

	public int getIntPage() {
		return intPage;
	}

	public void setIntPage(int intPage) {
		this.intPage = intPage;
	}

	public int getQuestionId() {
		return questionId;
	}

	public void setQuestionId(int questionId) {
		this.questionId = questionId;
	}

	// 问题列表
	public String questionGet() throws SQLException{
		HttpServletRequest request = ServletActionContext.getRequest();
		
		// pageInfoBean
		PageInfoBean pageInfoBean = new PageInfoBean();
		pageInfoBean.setIntPage(this.getIntPage());
		// questionBean
		QuestionBean questionBean = new QuestionBean();
		questionBean.setQuestionId(String.valueOf(this.getQuestionId()));
		// courseId
		int courseIdTemp = this.getCourseId();
		//questionId
		int questionId = this.getQuestionId();

		// 处理和设置pageInfoBean,userQuestionBean,userAnswerListBean
		// 获取问题
		UserQuestionBean userQuestionBean = new UserQuestionBean();
		userQuestionBean = questionService.userQuestionGet(questionBean);
		// 获取回复
		UserAnswerListBean userAnswerListBean =new UserAnswerListBean();
		userAnswerListBean = questionService.userAnswerListGet(questionBean, pageInfoBean);	
		
		request.setAttribute("userQuestionBean", userQuestionBean);
		request.setAttribute("userAnswerListBean", userAnswerListBean);
		request.setAttribute("pageInfoBean", pageInfoBean);
		request.setAttribute("courseId", courseIdTemp);
		request.setAttribute("questionId", questionId);

		return "Success";
	}
}
